<?php
/**
 * Author: Traveler
 * Time  : 2021/12/25 0025 15:56
 */

namespace app\validate;

use app\ErrorCode;
use think\Validate;

class UserValidate extends Validate
{
    /**
     * 验证规则
     *
     * @var string[]
     */
    protected $rule = [
        'name'      => 'require|max:16',
        'cellphone' => 'require|mobile|unique:\\app\\model\\UserModel', // 传入模型，为了兼容软删除
        'gender'    => 'require|in:0,1',
        'status'    => 'require|in:0,1',
    ];

    /**
     * 提示信息
     *
     * @var string[]
     */
    protected $message = [
        'name.require'      => ErrorCode::REQUIRE_USER_NAME,
        'name.max'          => ErrorCode::INVALID_USER_NAME_LEN,
        'cellphone.require' => ErrorCode::REQUIRE_CELLPHONE,
        'cellphone.mobile'  => ErrorCode::INVALID_CELLPHONE,
        'cellphone.unique'  => ErrorCode::DUPLICATE_CELLPHONE,
        'gender.require'    => ErrorCode::REQUIRE_GENDER,
        'gender.in'         => ErrorCode::INVALID_GENDER,
        'status.require'    => ErrorCode::REQUIRE_USER_STATUS,
        'status.in'         => ErrorCode::INVALID_USER_STATUS,
    ];
}